<?php
class users_model extends CI_Model {
	public function __construct()
    {
		parent::__construct();
		$this->load->database();
    }
	
	/* Basic DB opeartion*/
    
	public function get_all_user()
    {
		$query = $this->db->get('users');
		return $query->result_array();
    }
  
    public function get_by_id($openid)
    {
		$query = $this->db->get_where('users', array('openid' => $openid));
		return $query->row_array();
    }
  
    public function insert($data)
    {
		$this->db->insert('users',$data);
		return $this->db->insert_id();
	}
	
    public function update($openid,$data)
    {
		$this->db->update('users', $data, array('openid' => $openid));
		return $this->db->affected_rows();
    }
	
	public function delete($openid)
	{
		$this->db->delete('users', array('openid' => $openid)); 
		return $this->db->affected_rows();
	}
	
	/*Business logic opeartion*/
	
}
?>
